package org.stars.security;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class UserIdentityImpl implements UserIdentity {

	private static final long serialVersionUID = 7389869417638140668L;
	
	protected String username;
	protected String description;
	protected Set<String> roles;
	protected Set<String> functions;
	protected Map<String, Object> attributes;
	
	public UserIdentityImpl()
	{
		username="";
		roles=new HashSet<String>();
		functions=new HashSet<String>();
		attributes=new HashMap<String, Object>();
	}
	
	/* (non-Javadoc)
	 * @see org.stars.security.UserIdentity#isEnableTo(java.lang.String)
	 */
	@Override
	public boolean isEnableTo(String functionName) {
		if (functionName.contains(functionName))
		{
			return true;
		} else return false;
	}

	/* (non-Javadoc)
	 * @see org.stars.security.UserIdentity#isIdentityValid()
	 */
	@Override
	public boolean isIdentityValid() {
		if (username.length()==0) return false;
		
		return true;
	}

	/* (non-Javadoc)
	 * @see org.stars.security.UserIdentity#hasRole(java.lang.String)
	 */
	@Override
	public boolean hasRole(String roleName) {
		if (roles.contains(roleName))
		{
			return true;
		} else return false;
	}

	/* (non-Javadoc)
	 * @see org.stars.security.UserIdentity#getAttribute(java.lang.String)
	 */
	@Override
	public Object getAttribute(String attributeName) {
		return attributes.get(attributeName);
	}

	@Override
	public void setAttribute(String attributeName, Object value) {
		attributes.put(attributeName, value);		
	}

	@Override
	public String getUsername() {
		return username;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public Set<String> getRoles() {
		return roles;		
	}

	@Override
	public Set<String> getFunctions() {
		return functions;
	}


}
